﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vds2465Telegrams
{
	public abstract class UserData_AddressExt_1 : UserData_Address
	{
		// TODO page 28 bottom of spec mentions the higher nibble can be used for another address offset
		// but if 0x10 = eAddressExtension_1 the higher nibble is already "taken"

		#region private member variables

		private readonly eAddressExtension_1 _addressExtension;

		#endregion private member variables

		#region constructor

		public UserData_AddressExt_1(byte dataType, byte device, byte address, byte addressAddOn, eAddressExtension_1 addressExtension)
			: base(dataType, device, address, addressAddOn)
		{
			_addressExtension = addressExtension;
		}

		#endregion constructor

		#region getters

		public eAddressExtension_1 AddressExtension { get { return _addressExtension; } }

		#endregion getters

		#region ToString, Equals, GetHashCode

		public override int GetHashCode()
		{
			int hashCode = base.GetHashCode();			
			hashCode ^= (byte) _addressExtension;

			return hashCode;
		}

		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("(");
			stringBuilder.Append(ToStringProperties());
			stringBuilder.Append(")");

			return stringBuilder.ToString();
		}

		internal override string ToStringProperties()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(base.ToStringProperties());
			stringBuilder.Append(", ");
			
			stringBuilder.Append("AddressExtension='");
			stringBuilder.Append(AddressExtension);
			stringBuilder.Append("'");

			return stringBuilder.ToString();
		}

		public override bool Equals(object obj)
		{
			Type objType = obj.GetType();
			if (this.GetType() == objType)
			{
				UserData_AddressExt_1 userData02StatusChangeReport2Confirm2Compare = obj as UserData_AddressExt_1;
				return EqualsProperties(userData02StatusChangeReport2Confirm2Compare);
			}

			return false;
		}

		internal bool EqualsProperties(UserData_AddressExt_1 userData2Compare)
		{
			if (base.EqualsProperties(userData2Compare))
			{
				return (AddressExtension == userData2Compare.AddressExtension);
			}

			return false;
		}

		#endregion ToString, Equals, GetHashCode
	}
}
